home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dde2 / ddexl.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-05-16  |  4.3 KB  |  148 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "DDE Client to Excel"
  4.    ClientHeight    =   4290
  5.    ClientLeft      =   1320
  6.    ClientTop       =   1785
  7.    ClientWidth     =   7245
  8.    Height          =   4695
  9.    Left            =   1260
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4290
  13.    ScaleWidth      =   7245
  14.    Top             =   1440
  15.    Width           =   7365
  16.    Begin TextBox Text1 
  17.       Height          =   1095
  18.       Left            =   600
  19.       MultiLine       =   -1  'True
  20.       TabIndex        =   0
  21.       Text            =   "Data"
  22.       Top             =   1200
  23.       Width           =   2175
  24.    End
  25.    Begin CommandButton Command2 
  26.       Caption         =   "Manual Link / Update"
  27.       Height          =   375
  28.       Left            =   3600
  29.       TabIndex        =   2
  30.       Top             =   1200
  31.       Width           =   2235
  32.    End
  33.    Begin CommandButton Command1 
  34.       Caption         =   "Auto Link"
  35.       Height          =   375
  36.       Left            =   3600
  37.       TabIndex        =   1
  38.       Top             =   1800
  39.       Width           =   2265
  40.    End
  41.    Begin CommandButton Command4 
  42.       Caption         =   "Poke"
  43.       Height          =   375
  44.       Left            =   3600
  45.       TabIndex        =   3
  46.       Top             =   2400
  47.       Width           =   2280
  48.    End
  49.    Begin TextBox Text2 
  50.       Height          =   720
  51.       Left            =   570
  52.       MultiLine       =   -1  'True
  53.       ScrollBars      =   1  'Horizontal
  54.       TabIndex        =   4
  55.       Text            =   "Open Documents"
  56.       Top             =   2760
  57.       Width           =   2265
  58.    End
  59.    Begin CommandButton Command3 
  60.       Caption         =   "Get Document Names"
  61.       Height          =   450
  62.       Left            =   3600
  63.       TabIndex        =   5
  64.       Top             =   3000
  65.       Width           =   2415
  66.    End
  67.    Begin Label Label1 
  68.       Alignment       =   2  'Center
  69.       AutoSize        =   -1  'True
  70.       BorderStyle     =   1  'Fixed Single
  71.       Caption         =   "This form links to a document SERVER.XLS.  Excel is executed and the document is opened if necessary."
  72.       Height          =   615
  73.       Left            =   1440
  74.       TabIndex        =   6
  75.       Top             =   240
  76.       Width           =   3945
  77.       WordWrap        =   -1  'True
  78.    End
  79. Option Explicit
  80. Const NONE = 0         ' 0 - None
  81. Const LINK_SOURCE = 1    ' 1 - Source (forms only)
  82. Const LINK_AUTOMATIC = 1 ' 1 - Automatic (controls only)
  83. Const LINK_MANUAL = 2    ' 2 - Manual (controls only)
  84. Const LINK_NOTIFY = 3    ' 3 - Notify (controls only)
  85. Sub Command1_Click ()
  86.     Text1.LinkMode = NONE
  87.     Text1.LinkMode = LINK_AUTOMATIC
  88. End Sub
  89. Sub Command2_Click ()
  90.     Text1.LinkMode = NONE
  91.     Text1.LinkMode = LINK_MANUAL
  92.     Text1.LinkRequest
  93. End Sub
  94. Sub Command3_Click ()
  95.     text2.LinkMode = NONE
  96.     text2.LinkTopic = "Excel|system"
  97.     text2.LinkItem = "topics"
  98.     text2.LinkMode = LINK_MANUAL
  99.     text2.LinkRequest
  100. End Sub
  101. Sub Command4_Click ()
  102.     Text1.LinkMode = NONE
  103.     Text1.LinkMode = LINK_MANUAL
  104.     Text1.LinkPoke
  105. End Sub
  106. Sub Form_Load ()
  107.     Dim rc As Integer
  108.     Dim IsOpen As Integer
  109.     Dim TheCmd As String
  110.     'Test to see if App is running...
  111.     On Error GoTo startup
  112. reentry:
  113.     Text1.LinkMode = NONE
  114.     Text1.LinkTopic = "Excel|System"
  115.     Text1.LinkItem = "Topics"
  116.     Text1.LinkMode = LINK_MANUAL
  117.     Text1.LinkRequest
  118.     Text1.LinkTimeout = 300
  119.     'The linkitem TOPICS returns a list of all open spreadsheets
  120.     'Test if sheet is open.
  121.     IsOpen = InStr(UCase$(Text1.Text), UCase$("source.xls"))
  122.     text2.Text = Str$(IsOpen)
  123.     If IsOpen = 0 Then
  124.     'Document is not open
  125.     On Error GoTo nosheet
  126.     TheCmd = "[OPEN(" + """"
  127.     TheCmd = TheCmd$ + "c:\vbdemos\dde\source.xls" + """" + ",1)]"
  128.     Text1.LinkExecute TheCmd
  129.     End If
  130.     'Set link to correct row/cell location
  131.     Text1.LinkMode = NONE
  132.     Text1.LinkTopic = "Excel|SOURCE.XLS"
  133.     Text1.LinkItem = "R1C1"
  134.     Text1.LinkMode = LINK_AUTOMATIC
  135.     Exit Sub
  136. startup:
  137.     If Err = 282 Then
  138.     rc = Shell("c:\excel\Excel c:\vbdemos\dde\source.xls", 7)
  139.     Resume reentry
  140.     Else
  141.     MsgBox "Unknown DDE error."
  142.     Exit Sub
  143.     End If
  144. nosheet:
  145.     MsgBox "Unable to open sheet."
  146.     Exit Sub
  147. End Sub
  148.